/*********************************************************************************
 *      Copyright:  (C) 2025 TBW
 *                  All rights reserved.
 *
 *       Filename:  sqlite.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(19/05/25)
 *         Author:  huang zixiao <2027838269@qq.com>
 *      ChangeLog:  1, Release initial version on "19/05/25 15:52:12"
 *                 
 ********************************************************************************/
#include <sqlite3.h>
#include <stdio.h>
void sqlite(char *sqlite_filename, sqlite3 *db, char *sql, int (*callback)(void*, int, char**, char**))
{

    char    *err_msg = NULL;
    int            rv = -1;
    rv = sqlite3_open(sqlite_filename, &db);
    if(rv != SQLITE_OK)
    {
        printf("cannot open %s:%s\n", sqlite_filename, sqlite3_errmsg(db));
        sqlite3_close(db);
        return;
    }
    //printf("open %s successfully!\n", sqlite_filename);

    rv = sqlite3_exec(db, sql, callback, NULL, &err_msg);
    if(rv != SQLITE_OK)
    {
        printf("sql error:%s\n", err_msg);
        sqlite3_free(err_msg);
        sqlite3_close(db);
        return;
    }
    printf("exec '%s' successfully\n", sql);

    sqlite3_close(db);
    return;
}
